//
//  ViewController.m
//  UI_Block
//
//  Created by Scott on 16/1/18.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "ViewController.h"
#import "SecondViewController.h"
#import "CustomView.h"
#import "NetworkHandle.h"

@interface ViewController ()

@property (retain, nonatomic) IBOutlet UILabel *label;
@property (retain, nonatomic) IBOutlet CustomView *customView;

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    [self.customView viewDidClick:^(CustomView *viem) {
        
        NSLog(@"%ld", viem.retainCount);
        NSLog(@"%s", __func__);
    }];
    
    
    [self handleData];
    
}

- (void)handleData {
    
    
    [NetworkHandle networkOperationWithUrl:@"http://api.map.baidu.com/place/v2/search?query=银行&region=大连&output=json&ak=6E823f587c95f0148c19993539b99295" completeHandle:^(id result) {
        
        NSLog(@"%@", result);
        
    }];
    
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
    
    NSLog(@"%ld", self.retainCount);
    
    __block typeof(self)weakSelf = self;
    SecondViewController *second = [segue destinationViewController];
    
    second.block = ^(NSString *str) {
        
        self.label.text = str;
    };
    
    NSLog(@"%ld", self.retainCount);
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}









- (void)dealloc {
    [_label release];
    [_customView release];
    [super dealloc];
}
@end
